package com.meida.module.bus.provider.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.google.common.collect.Lists;
import com.meida.common.mybatis.base.service.impl.BaseServiceImpl;
import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.mybatis.query.CriteriaSave;
import com.meida.module.bus.client.entity.BusSupplier;
import com.meida.module.bus.provider.mapper.BusSupplierMapper;
import com.meida.module.bus.provider.service.BusSupplierService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 分包商接口实现类
 *
 * @author flyme
 * @date 2020-10-22
 */
@Service
@Transactional(rollbackFor = Exception.class)
//@DS("dbr")
public class BusSupplierServiceImpl extends BaseServiceImpl<BusSupplierMapper, BusSupplier> implements BusSupplierService {

    @Override
    public ResultBody beforeAdd(CriteriaSave cs, BusSupplier supplier, EntityMap extra) {
        return ResultBody.ok();
    }



    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<BusSupplier> cq, BusSupplier supplier, EntityMap requestMap) {
//      cq.orderByDesc("supplier.createTime");
      return ResultBody.ok();
    }

//    @Override
//    public void afterPageList(CriteriaQuery<BusSupplier> cq, List<EntityMap> data, ResultBody resultBody) {
//        data.stream().forEach(dataObj->{
//            dataObj.put("supplierName", dataObj.get("VENDORNAME"));
//            dataObj.put("supplierCode", dataObj.get("VENDORCODE"));
//            dataObj.put("supplierId", dataObj.get("VENDORID"));
//        });
//        resultBody.data(data);
//    }
//
//    @Override
//    public ResultBody afterListEntityMap(CriteriaQuery<BusSupplier> cq, List<EntityMap> data, ResultBody resultBody) {
//        data.stream().forEach(dataObj->{
//            dataObj.put("supplierName", dataObj.get("VENDORNAME"));
//            dataObj.put("supplierCode", dataObj.get("VENDORCODE"));
//            dataObj.put("supplierId", dataObj.get("VENDORID"));
//        });
//        resultBody.data(data);
//        return resultBody;
//    }

    @Override
    public List<BusSupplier> getallSupplier() {
        CriteriaQuery<BusSupplier> cq=new  CriteriaQuery(BusSupplier.class);
        cq.select("DISTINCT supplierName");
//        List<EntityMap> data = selectEntityMap(cq);
//
//        List<BusSupplier> outSuppliers = Lists.newArrayList();
//        data.stream().forEach(srmObj->{
//            BusSupplier busSupplier = new BusSupplier();
////            busSupplier.setSupplierId(srmObj.getLong("VENDORID"));
//            busSupplier.setSupplierName(srmObj.get("VENDORNAME"));
////            busSupplier.setSupplierCode(srmObj.get("VENDORCODE"));
//            outSuppliers.add(busSupplier);
//        });
//        return outSuppliers;
        return list(cq);
    }
}
